package com.neusoft.ecommerce.dbhelper;

import java.util.List;

/**
 * 
 * @author YinKuenTam
 *
 * @param <T>
 */
public class LayuiPager<T> {
	private Integer code;
	private String msg;
	private Integer count;
	private List<T> data;
	
	/**
	 * layui默认传递的页码
	 */

	
	private Integer page;

	/**
	 * layui默认传递的分页大小
*/
	private Integer limit;

	
	/**
	 *  .查询条件
	 */
	private T  condition;


	public LayuiPager(Integer page, Integer limit) {
		this.page = page;
		this.limit = limit;
	}

	public LayuiPager(Integer page, Integer limit, T condition) {
		this.page = page;
		this.limit = limit;
		this.condition = condition;
	}


	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		// 页码不能小于1
        if (page != null && page >= 1) {
            this.page = page;
        }
	}

	public Integer getLimit() {
		return limit;
	}

	public void setLimit(Integer limit) {
		// 分页大小必须大于等于1
        if (limit != null && limit >= 1) {
            this.limit = limit;
        }
	}

	public T getCondition() {
		return condition;
	}

	public void setCondition(T condition) {
		this.condition = condition;
	}
	
	
	 /**
     * 计算分页查询参数-从数据库的第几行数据开始查询
     *
     * @return
     */
    public Integer getStart() {
        if (page >= 1) {
            return (page - 1) * limit;
        }
        // 没有分页查询或没有数据,返回0
        return 0;
    }
    
    
    /**
     * 计算分页查询参数-查询到数据库的第几行数据
     *
     * @return
     */
    public Integer getEnd() {
        if (page >= 1) {
            return page * limit;
        }
        // 没有分页查询或没有数据,返回0
        return 0;
    }

	@Override
	public String toString() {
		return "LayuiPager [code=" + code + ", msg=" + msg + ", count=" + count + ", data=" + data + ", page=" + page
				+ ", limit=" + limit + ", condition=" + condition + "]";
	}
    
    
}
